package com.to.aboomy.banner;

import ohos.agp.components.Component;
import ohos.agp.components.PageSlider;

/**
 * 尺寸变化器
 *
 * @since 2021-07-21
 */
public class ScaleInTransformer implements BannerViewPager.PageTransformer {

    @Override
    public void transformerPage(BannerViewPager.PageType pageType, Component page, float offset, float offsetPixels) {
        float scale = 0.8f;
        switch (pageType) {
            case PREVIOUS:
                if (offsetPixels <= 0) {
                    scale = 0.8f + offset * 0.3f;
                    if (scale > 1) {
                        scale = 1;
                    }
                }
                break;
            case CURRENT:
                scale = 1 - offset * 0.3f;
                if (scale < 0.8f) {
                    scale = 0.8f;
                }
                break;
            case NEXT:
                if (offsetPixels >= 0) {
                    scale = 0.8f + offset * 0.3f;
                    if (scale > 1) {
                        scale = 1;
                    }
                }
                break;
        }
        page.setScale(scale, scale);
    }
}
